<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../common/jquery.js"></script>
	</head>

	<body>
	</body>
	<script>
		var copy = {
			jqCopy: function() {
				//$.extend相当于用来整合对象
				//还要考虑如果有重名的情况
				var obj1 = {
					name: 'ygy',
					height: 175
				}
				var obj2 = {
					height: 172
				}
				var obj3 = {
					weight: "20kg"
				}
				var objend = $.extend(obj1, obj2, obj3);
				console.log(objend);
				obj2.height = 180;
				console.log(objend);
			},
			/*浅拷贝
			 当父对象的属性为字符串或其他值的时候可以拷贝，但是
			 当父对象有属性也是对象的时候，就会形成对象引用*/
			simpleQianCopy:function(iniObj){
				var obj = {};
				for(var i in iniObj){
					obj[i] = iniObj[i];
				}
				return obj;
			},
			/*这种浅拷贝也是一样，当为对象时，就形成对象引用了*/
			assignCopy:function(iniObj){
				var obj = {};
				obj = Object.assign({},iniObj);
				return obj;
			},
			/*深拷贝
			 缺点是构造函数会改变，而且只能处理json结构的对象*/
			parseDeepCopy:function(iniObj){
				var obj = JSON.parse(JSON.stringify(iniObj));
				return obj;
			},
			objectCreateCopy:function(iniObj){
				var obj = {};
				obj = Object.create(iniObj);
				return obj;
			}
		}
		var obj = {name:"ygy",a:{height:170}};
		var a = copy.objectCreateCopy(obj);
		a.name = "yangguanyong";
		a.a.height = 190;
		console.log(obj.name);
		console.log(obj.a.height);
	</script>

</html>